package com.guyu.plugin.sms.core;


import com.guyu.plugin.redisson.util.RedisUtils;
import org.dromara.sms4j.api.dao.SmsDao;

import java.time.Duration;

public class GuyuSmsDao implements SmsDao {

    private static final String SMS_CACHE_PREFIX = "guyu:";

    @Override
    public void set(String key, Object value, long cacheTime) {
        RedisUtils.setCacheObject(SMS_CACHE_PREFIX + key, value, Duration.ofSeconds(cacheTime));
    }

    @Override
    public void set(String key, Object value) {
        RedisUtils.setCacheObject(SMS_CACHE_PREFIX + key, value);
    }

    @Override
    public Object get(String key) {
        return RedisUtils.getCacheObject(SMS_CACHE_PREFIX + key);
    }

    @Override
    public Object remove(String key) {
        return RedisUtils.deleteObject(SMS_CACHE_PREFIX + key);
    }

    @Override
    public void clean() {
        RedisUtils.deleteByPatternAsync(SMS_CACHE_PREFIX + "*");
    }
}
